package com.nantaphop.hovertouchviewexample.widget;


import com.nantaphop.hovertouchview.HoverTouchAble;

import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.components.Image;
import ohos.agp.components.element.Element;
import ohos.agp.components.element.PixelMapElement;
import ohos.agp.utils.TextAlignment;
import ohos.agp.window.dialog.ToastDialog;
import ohos.app.Context;
import ohos.media.image.PixelMap;

/**
 * MyThumbnail class for image thumbnails hover
 */

public class MyThumbnail extends Image implements HoverTouchAble {
    private ToastDialog toastDialog;
    private Element element;

    public MyThumbnail(Context context) {
        super(context);
    }

    public MyThumbnail(Context context, AttrSet attrs) {
        super(context, attrs);
    }

    @Override
    public Component getHoverView() {
        PixelMap pixelMap = getPixelMap();
        Element element = (Element) (new PixelMapElement(pixelMap));

        return new MyThumbnailExpand(getContext(), element, "Description Text For Photo\nNoted : This is just demo view you better to make your own view.");
    }

    @Override
    public int getHoverAnimateDuration() {
        return 300;
    }

    @Override
    public void onStartHover() {
        showToast("Start Hover");
    }

    @Override
    public void onStopHover() {
        showToast("Stop Hover");
    }

    private void showToast(String message) {
        if (toastDialog != null) {
            toastDialog.cancel();
            toastDialog = null;
        }
        toastDialog = new ToastDialog(getContext());
        toastDialog.setText(message);
        toastDialog.setAlignment(TextAlignment.BOTTOM);
        toastDialog.show();
    }

}